home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v2.1 / Amiga Developer CD v2.1.iso / Contributions / Haage_&_Partner / Storm-Projects / NDKExamples1 / intuition / 8hamdemo.c < prev    next >
C/C++ Source or Header  |  1999-04-16  |  9KB  |  394 lines

  1. /*
  2.  * 8hamdemo.c - shows off 262144 colors simultaneously
  3.  *
  4.  * (c) Copyright 1992-1996 Amiga International, Inc. All rights reserved.
  5.  *
  6.  * This software is provided as-is and is subject to change; no warranties
  7.  * are made.  All use is at your own risk.  No liability or responsibility
  8.  * is assumed.
  9.  *
  10.  */
  11.  
  12. #include <graphics/gfxbase.h>
  13. #include <graphics/displayinfo.h>
  14. #include <intuition/intuitionbase.h>
  15.  
  16. #include <clib/exec_protos.h>
  17. #include <clib/graphics_protos.h>
  18. #include <clib/diskfont_protos.h>
  19. #include <clib/intuition_protos.h>
  20.  
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23.  
  24. /*----------------------------------------------------------------------*/
  25.  
  26. void error_exit(STRPTR errorstring);
  27.  
  28. int CXBRK(void) { return(0); }
  29. void chkabort(void) { return; }
  30.  
  31. /*----------------------------------------------------------------------*/
  32.  
  33. struct Library *DiskfontBase = NULL;
  34. struct GfxBase *GfxBase = NULL;
  35. struct IntuitionBase *IntuitionBase = NULL;
  36. struct Screen *myscreen = NULL;
  37. struct Window *mywindow = NULL;
  38. struct BitMap *bm[2] = {NULL,NULL};
  39. struct RastPort temprp;
  40. struct TextFont *font = NULL;
  41.  
  42. /*----------------------------------------------------------------------*/
  43.  
  44. UWORD pens[] =
  45. {
  46.     0, /* DETAILPEN */
  47.     1, /* BLOCKPEN    */
  48.     1, /* TEXTPEN    */
  49.     2, /* SHINEPEN    */
  50.     1, /* SHADOWPEN    */
  51.     3, /* FILLPEN    */
  52.     1, /* FILLTEXTPEN    */
  53.     0, /* BACKGROUNDPEN    */
  54.     2, /* HIGHLIGHTTEXTPEN    */
  55.  
  56.     1, /* BARDETAILPEN    */
  57.     2, /* BARBLOCKPEN    */
  58.     1, /* BARTRIMPEN    */
  59.  
  60.     (UWORD)~0,
  61. };
  62.  
  63.  
  64. /* Color table to pass to SA_Colors32 or LoadRGB32() */
  65. ULONG colortable[] =
  66. {
  67.     0x00040000,    /* 5 colors to load, from zero */
  68.  
  69.     0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA,    /* Gray */
  70.     0x00000000, 0x00000000, 0x00000000,    /* Black */
  71.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,    /* White */
  72.     0x66666666, 0x88888888, 0xBBBBBBBB,    /* Blue-gray */
  73.  
  74.     0x00000000,    /* terminator */
  75. };
  76.  
  77. /*----------------------------------------------------------------------*/
  78.  
  79. #define PLOTWIDTH 64
  80. #define PLOTHEIGHT 64
  81.  
  82.  
  83. /*----------------------------------------------------------------------*/
  84.  
  85. /* Let's arrange the blue values in a spiral, just to be cute.
  86.  * We'll do it with a table instead of an algorithm out of
  87.  * laziness.
  88.  */
  89. int bluespiral1[] =
  90. {
  91.     56, 55, 54, 53, 52, 51, 50, 49,
  92.     57, 30, 29, 28, 27, 26, 25, 48,
  93.     58, 31, 12, 11, 10,  9, 24, 47,
  94.     59, 32, 13,  2,  1,  8, 23, 46,
  95.     60, 33, 14,  3,  0,  7, 22, 45,
  96.     61, 34, 15,  4,  5,  6, 21, 44,
  97.     62, 35, 16, 17, 18, 19, 20, 43,
  98.     63, 36, 37, 38, 39, 40, 41, 42,
  99. };
  100.  
  101. int bluespiral2[] =
  102. {
  103.     60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45,
  104.     61, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 44,
  105.     62, 27,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 43,
  106.     63, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
  107. };
  108.  
  109. /*----------------------------------------------------------------------*/
  110.  
  111. struct TextAttr topaz80 =
  112. {
  113.     "topaz.font",
  114.     8,
  115.     0,
  116.     0,
  117. };
  118.  
  119. struct TextAttr preffont =
  120. {
  121.     "times.font",
  122.     15,
  123.     0,
  124.     0,
  125. };
  126.  
  127. #define MOD_BLUE    64
  128. #define MOD_RED        128
  129. #define MOD_GREEN    192
  130.  
  131. #define XOFF 6
  132. #define YOFF 5
  133.  
  134. void main(int argc, char **argv)
  135. {
  136.     int blue, x, ybase, column;
  137.     int redreverse, red, dred;
  138.     int left, top, width, height, b;
  139.     int perrow = 16;
  140.     int *bluespiral = bluespiral2;
  141.     struct TextAttr *scfont = &topaz80;
  142.  
  143.     ULONG displayID = NTSC_MONITOR_ID | SUPERHAMLACE_KEY;
  144.     int overscan = OSCAN_TEXT;
  145.  
  146.     if ( ( argc > 1 ) && ( *argv[1] == '?' ) )
  147.     {
  148.     printf("8HAMDemo [S|P|D|N]\n");
  149.     printf("- S = use Super72\n");
  150.     printf("- P = use PAL hires-lace\n");
  151.     printf("- D = use double-PAL hires-lace\n");
  152.     printf("- N = use NTSC superhires-lace [default]\n");
  153.     }
  154.     else
  155.     {
  156.     if ( ( argc > 1 ) && ( ( *argv[1] == 'D' ) || ( *argv[1] == 'd' ) ) )
  157.     {
  158.         displayID = DBLPALHIRESHAMFF_KEY;
  159.         overscan = OSCAN_MAX;
  160.         perrow = 8;
  161.             bluespiral = bluespiral1;
  162.     }
  163.  
  164.     if ( ( argc > 1 ) && ( ( *argv[1] == 'P' ) || ( *argv[1] == 'p' ) ) )
  165.     {
  166.         displayID = PAL_MONITOR_ID | HIRESHAMLACE_KEY;
  167.         overscan = OSCAN_MAX;
  168.         perrow = 8;
  169.             bluespiral = bluespiral1;
  170.     }
  171.  
  172.     if ( ( argc > 1 ) && ( ( *argv[1] == 'S' ) || ( *argv[1] == 's' ) ) )
  173.     {
  174.         displayID = 0x89824;
  175.         overscan = OSCAN_TEXT;
  176.         perrow = 8;
  177.             bluespiral = bluespiral1;
  178.     }
  179.  
  180.     if ( ( argc > 1 ) && ( ( *argv[1] == 'N' ) || ( *argv[1] == 'n' ) ) )
  181.     {
  182.         displayID = NTSC_MONITOR_ID | SUPERHAMLACE_KEY;
  183.         overscan = OSCAN_TEXT;
  184.         perrow = 16;
  185.             bluespiral = bluespiral2;
  186.     }
  187.  
  188.     if (!( GfxBase = (struct GfxBase *)
  189.         OpenLibrary("graphics.library", 39L) ))
  190.         {
  191.         error_exit("Couldn't open Gfx V39\n");
  192.         }
  193.  
  194.     if (!( IntuitionBase = (struct IntuitionBase *)
  195.         OpenLibrary("intuition.library", 39L) ))
  196.         {
  197.         error_exit("Couldn't open Intuition V39\n");
  198.         }
  199.  
  200.     if (!( DiskfontBase = (struct Library *)
  201.         OpenLibrary("diskfont.library", 37L) ))
  202.         {
  203.         error_exit("Couldn't open Diskfont V37\n");
  204.         }
  205.  
  206.     if ( font = OpenDiskFont( &preffont ) )
  207.     {
  208.         scfont = &preffont;
  209.     }
  210.  
  211.     InitRastPort( &temprp );
  212.     bm[0] = AllocBitMap( PLOTWIDTH, PLOTHEIGHT, 8, BMF_INTERLEAVED|BMF_CLEAR, NULL );
  213.     temprp.BitMap = bm[0];
  214.     for ( x=0; x<64; x++ )
  215.     {
  216.         SetAPen( &temprp, MOD_GREEN+x );
  217.         Move( &temprp, x, 0 );
  218.         Draw( &temprp, x, 63 );
  219.     }
  220.  
  221.     bm[1] = AllocBitMap( PLOTWIDTH, PLOTHEIGHT, 8, BMF_INTERLEAVED|BMF_CLEAR, NULL );
  222.     temprp.BitMap = bm[1];
  223.  
  224.     for ( x=0; x<64; x++ )
  225.     {
  226.         SetAPen( &temprp, MOD_GREEN+63-x );
  227.         Move( &temprp, x, 0 );
  228.         Draw( &temprp, x, 63 );
  229.     }
  230.  
  231.     if (!(myscreen = OpenScreenTags(NULL,
  232.         SA_DisplayID, displayID,
  233.         SA_Overscan, overscan,
  234.         /*  Other tags can go here: */
  235.         SA_Font, scfont,
  236.         SA_Depth, 8,
  237.         SA_AutoScroll, 1,
  238.         SA_Pens, pens,
  239.         SA_Interleaved, TRUE,
  240.         SA_Title, "8-plane HAM Demo",
  241.         SA_Colors32, colortable,
  242.         SA_Behind, TRUE,
  243.         TAG_DONE )))
  244.         {
  245.         error_exit("Couldn't open screen\n");
  246.         }
  247.  
  248.     width = 14 + (perrow*65);
  249.     height = 10 + scfont->ta_YSize + (64/perrow)*64;
  250.     left = ( myscreen->Width - width - scfont->ta_YSize - 2 ) / 2;
  251.     top = ( myscreen->Height - height ) / 2;
  252.  
  253.     if (!( mywindow = OpenWindowTags(NULL,
  254.         WA_Left, left,
  255.         WA_Top, top,
  256.         WA_Width, width,
  257.         WA_Height, height,
  258.         WA_MinWidth, 50,
  259.         WA_MinHeight, 40,
  260.         WA_MaxWidth, -1,
  261.         WA_MaxHeight, -1,
  262.         WA_IDCMP, IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY,
  263.         WA_DepthGadget, TRUE,
  264.         WA_DragBar, TRUE,
  265.         WA_Title, "262144 Colors!",
  266.         WA_CloseGadget, TRUE,
  267.         WA_NoCareRefresh, TRUE,
  268.         WA_SmartRefresh, TRUE,
  269.         WA_CustomScreen, myscreen,
  270.         WA_Activate, TRUE,
  271.         TAG_DONE ) ))
  272.         {
  273.         error_exit("Couldn't open window\n");
  274.         }
  275.  
  276.     b = 0;
  277.     ybase = 0;
  278.     column = 0;
  279.     redreverse=0;
  280.  
  281.     for ( blue = 0; blue < 64; blue++ )
  282.     {
  283.         if ( column == 0 )
  284.         {
  285.         int dy;
  286.  
  287.         SetAPen( mywindow->RPort, 1 );
  288.         Move( mywindow->RPort, XOFF-1, (YOFF+scfont->ta_YSize)+ybase );
  289.         Draw( mywindow->RPort, XOFF-1, (YOFF+scfont->ta_YSize)+ybase+63 );
  290.  
  291.         for ( dy = 0; dy < 64; dy++ )
  292.         {
  293.             if ( redreverse )
  294.             {
  295.             SetAPen( mywindow->RPort, MOD_RED + 63-dy );
  296.             }
  297.             else
  298.             {
  299.             SetAPen( mywindow->RPort, MOD_RED + dy );
  300.             }
  301.             WritePixel( mywindow->RPort, XOFF, (YOFF+scfont->ta_YSize)+ybase+dy );
  302.         }
  303.         }
  304.  
  305.         SetAPen( mywindow->RPort, MOD_BLUE+63-bluespiral[blue]);
  306.         Move( mywindow->RPort, XOFF+column*65+1, (YOFF+scfont->ta_YSize)+ybase );
  307.         Draw( mywindow->RPort, XOFF+column*65+1, (YOFF+scfont->ta_YSize)+ybase+63 );
  308.  
  309.         BltBitMapRastPort( bm[b], 0, 0,
  310.         mywindow->RPort, XOFF+column*65 + 2, (YOFF+scfont->ta_YSize)+ybase,
  311.         PLOTWIDTH, PLOTHEIGHT, 0xC0 );
  312.         b = 1-b;
  313.  
  314.         column++;
  315.         if ( column == perrow )
  316.         {
  317.         column = 0;
  318.         ybase += 64;
  319.         redreverse = 1-redreverse;
  320.         }
  321.     }
  322.     ScreenToFront( myscreen );
  323.     dred = 1; red = 0;
  324.     /* Exit on break or on any IntuiMessage */
  325.     while ( !( SetSignal(0,0) & ( ( 1 << mywindow->UserPort->mp_SigBit ) | SIGBREAKF_CTRL_C ) ) )
  326.     {
  327.         ScrollRaster( mywindow->RPort, 0, -1, XOFF, (YOFF+scfont->ta_YSize), XOFF, (YOFF+scfont->ta_YSize)+(4096/perrow)-1 );
  328.         SetAPen( mywindow->RPort, MOD_RED + red );
  329.         red += dred;
  330.         if ( red == -1 )
  331.         {
  332.         dred = 1;
  333.         red = 0;
  334.         }
  335.         else if (red == 64 )
  336.         {
  337.         red = 63;
  338.         dred = -1;
  339.         }
  340.         WritePixel( mywindow->RPort, XOFF, (YOFF+scfont->ta_YSize) );
  341.     }
  342.     }
  343.     error_exit(NULL);
  344. }
  345.  
  346.  
  347. /*----------------------------------------------------------------------*/
  348.  
  349. void error_exit(STRPTR errorstring)
  350.  
  351.     {
  352.     if (mywindow)
  353.     {
  354.     ScreenToBack(myscreen);
  355.     CloseWindow(mywindow);
  356.     }
  357.  
  358.     if (myscreen)
  359.     {
  360.     CloseScreen(myscreen);
  361.     }
  362.  
  363.     if ( bm[1] ) FreeBitMap( bm[1] );
  364.     if ( bm[0] ) FreeBitMap( bm[0] );
  365.  
  366.     if (font) CloseFont(font);
  367.  
  368.     if (DiskfontBase)
  369.     {
  370.     CloseLibrary(DiskfontBase);
  371.     }
  372.  
  373.     if (IntuitionBase)
  374.     {
  375.     CloseLibrary((struct Library *)IntuitionBase);
  376.     }
  377.  
  378.     if (GfxBase)
  379.     {
  380.     CloseLibrary((struct Library *)GfxBase);
  381.     }
  382.  
  383.     if (errorstring)
  384.     {
  385.     printf(errorstring);
  386.     exit(20);
  387.     }
  388.  
  389.     exit(0);
  390.     }
  391.  
  392.  
  393. /*----------------------------------------------------------------------*/
  394.